import { request } from '@/utils/request'
import type { Customer, CustomerSearch } from '@/types/customer'
import type { PageQuery } from '@/types/api'

// 获取客户列表
export function getCustomerList(params?: CustomerSearch) {
  return request<Customer[]>({
    url: '/customer/list',
    method: 'get',
    params
  })
}

// 分页获取客户列表
export function getCustomerPage(params: PageQuery & CustomerSearch) {
  return request<{
    rows: Customer[]
    total: number
    pages?: number
    current?: number
    size?: number
  }>({
    url: '/customer/page',
    method: 'get',
    params
  })
}

// 获取客户详情
export function getCustomerDetail(customerId: number) {
  return request<Customer>({
    url: `/customer/${customerId}`,
    method: 'get'
  })
}

// 新增客户
export function addCustomer(data: Partial<Customer>) {
  return request({
    url: '/customer',
    method: 'post',
    data
  })
}

// 修改客户
export function updateCustomer(data: Partial<Customer>) {
  return request({
    url: '/customer',
    method: 'put',
    data
  })
}

// 删除客户
export function deleteCustomer(customerId: number) {
  return request({
    url: `/customer/${customerId}`,
    method: 'delete'
  })
}